package DroidEye.Servlet.TeacherServlet;

import DroidEye.DAO.TeacherDAO;
import DroidEye.Servlet.Common.EncodingSetter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/TeacherTeachServlet", name = "TeacherTeachServlet")
public class TeacherTeachServlet extends HttpServlet {
    private static final long serialVersionUID = -2267738860775080289L;

    @Autowired
    private TeacherDAO teacherDAO;
    
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        EncodingSetter.setEncoding(request, response);
        String thisStudentID = request.getParameter("thisStudentID");
        String projectTeach = request.getParameter("projectTeach");

        if (teacherDAO.addProjectTeach(thisStudentID, projectTeach)&&
                teacherDAO.changeProjectProgress(thisStudentID,"已辅导，待通过")) {
            PrintWriter out = response.getWriter();
            out.print("<script language='javascript'>alert('辅导信息添加完毕!');window.location.href='TeacherHasLoginTestRight.jsp';</script>");
//            response.setHeader("refresh", "0;URL=TeacherHasLoginTestRight.jsp");
        } else {
            PrintWriter out = response.getWriter();
            out.print("<script language='javascript'>alert('辅导信息添加出现问题！')</script>");
            response.setHeader("refresh", "0;URL=TeacherTeachProject.jsp");
        }
    }
}
